package lzy.controller;

import lzy.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import jakarta.servlet.http.HttpSession;

@Controller
public class FarmerController {
    @GetMapping("/user/dashboard")
    public String userbDashboard(HttpSession session, RedirectAttributes redirectAttributes, Model model) {
        User user = (User) session.getAttribute("user");
        if (user == null) {
            redirectAttributes.addFlashAttribute("error", "请先登录！");
            return "redirect:/login";
        }
        if (!"USERB".equals(user.getRole())) {
            redirectAttributes.addFlashAttribute("error", "您没有权限访问此页面！");
            return "redirect:/login";
        }
        model.addAttribute("user", user);
        return "user/dashboard";
    }
} 